<%--
  Created by IntelliJ IDEA.
  User: 几何
  Date: 2022/4/12
  Time: 16:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<html>
<head>
    <title>Document</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        img {
            float: left;
            width: 300px;
            height: 300px;
            margin-left: 300px;
            margin-top: 100px;
            border-radius: 50%;

        }

        body {
            height: 85vh;
            background-image: linear-gradient(to right top, rgba(224, 73, 13, 0.4), rgba(4, 149, 245, 0.5)); /*youx*/
        }

        .mydiv {
            width: 500px;
            background-color: #19191960; /*mei*/
            margin: 120px auto 0;
            border-radius: 24px;
            text-align: center;
            padding: 36px 0px 36px;
            margin-right: 200px;

        }

        .input_1, span {
            display: block;
            margin: 0px auto 20px;
            text-align: center;
        }

        .input_1 {
            background-color: transparent;
            color: white;
            height: 35px;
            width: 200px;
            border: 2px solid #3498db; /*mei*/
            border-radius: 24px;
            outline: none;
            transition: .3s;
        }

        .input_1::-webkit-input-placeholder { /*youx*/
            color: #a3a3a3;
        }

        .input_1:focus {
            border: 2px solid green; /*mei*/
            width: 230px;
        }

        .input_2 {
            width: 120px;
            height: 35px;
            border-radius: 20px;
            outline: none;
            border: 2px solid #2ecc71;
            background-color: transparent;
            color: white;
            transition: .3s;
            display: none;
            margin-left: 190px;
        }

        .input_2:hover {
            background-color: #2ecc71; /*mei*/
            box-shadow: rgba(0, 0, 0, 0.6) 1px 1px 5px;
        }

        h2 {
            margin-bottom: 20px;
        }

    </style>
    <script text="text/javascript">
        window.onload = function () {
            var user = document.getElementById("user");
            var userInfo = document.getElementById("userInfo");
            var pwd = document.getElementById("pwd");
            var pwdInfo = document.getElementById("pwdInfo");
            var pwd2 = document.getElementById("pwd2");
            var pwd2Info = document.getElementById("pwd2Info");
            var but = document.getElementById("but");


            var a = 0;
            var b = 0;
            var c = 0;
            user.onkeyup = function () {
                var uPattern = /^[a-zA-Z0-9_-]{6,8}$/;
                var val = user.value.trim();
                if (val == "") {
                    userInfo.innerText = "内容不能为空";
                    userInfo.style.color = "red";
                    a = 0;
                    if (a == 1 && b == 1 && c == 1) {
                        but.style.display = "block";
                    } else {
                        but.style.display = "none";
                    }
                } else if (!uPattern.test(val)) {
                    userInfo.innerText = "输入不规范,至少6-8个字符，只允许字母和数字";
                    userInfo.style.color = "red";
                    a = 0;
                    if (a == 1 && b == 1 && c == 1) {
                        but.style.display = "block";
                    } else {
                        but.style.display = "none";
                    }
                } else {

                    var userName = $("#user").val();
                    $.ajax({
                        url: "${pageContext.request.contextPath}/ajaxuser/signUserName",
                        data: {"userName": userName},
                        success: function (data) {
                            if (!data) {
                                userInfo.innerText = "用户名重复";
                                userInfo.style.color = "red";
                                b = 0;
                                but.style.display = "none";
                            } else {
                                userInfo.innerText = "OK";
                                userInfo.style.color = "#2ecc71";
                                b = 1;
                                a = 1;
                                if (a == 1 && b == 1 && c == 1) {
                                    but.style.display = "block";
                                } else {
                                    but.style.display = "none";
                                }
                            }
                        }
                    })
                }
            };

            pwd.onblur = function () {
                var uPattern = /^[a-zA-Z0-9_-]{6,10}$/;
                var val = pwd.value;
                if (!val) {
                    pwdInfo.innerText = "内容不能为空";
                    pwdInfo.style.color = "red";
                    b = 0
                    if (a == 1 && b == 1 && c == 1) {
                        but.style.display = "block";
                    } else {
                        but.style.display = "none";
                    }
                } else if (!uPattern.test(val)) {
                    pwdInfo.innerText = "输入不规范至少6-10个字符，只允许字母和数字";
                    pwdInfo.style.color = "red";
                    b = 0;
                    if (a == 1 && b == 1 && c == 1) {
                        but.style.display = "block";
                    } else {
                        but.style.display = "none";
                    }
                } else {
                    pwdInfo.innerText = "OK";
                    pwdInfo.style.color = "#2ecc71";
                    b = 1;
                    if (a == 1 && b == 1 && c == 1) {
                        but.style.display = "block";
                    } else {
                        but.style.display = "none";
                    }
                }
            };

            pwd2.onblur = function () {
                var userpswd = pwd.value.trim();
                var confirmpswd = pwd2.value;
                if (!confirmpswd) {
                    pwd2Info.innerText = "请再次输入密码";
                    pwd2Info.style.color = "red";
                    c = 0;
                    if (a == 1 && b == 1 && c == 1) {
                        but.style.display = "block";
                    } else {
                        but.style.display = "none";
                    }

                } else if (userpswd != confirmpswd) {
                    pwd2Info.innerText = "密码不一致";
                    pwd2Info.style.color = "red";
                    c = 0;
                    if (a == 1 && b == 1 && c == 1) {
                        but.style.display = "block";
                    } else {
                        but.style.display = "none";
                    }

                } else {
                    pwd2Info.innerText = "OK";
                    pwd2Info.style.color = "#2ecc71";
                    c = 1;
                    if (a == 1 && b == 1 && c == 1) {
                        but.style.display = "block";
                    } else {
                        but.style.display = "none";
                    }
                }
            };

        }
    </script>

</head>
<body>
<img src="${pageContext.request.contextPath}/images/logo.jpg">
<div class="mydiv" id="mydiv">
    <h2>注册</h2><br/>
    已有帐号？<a href="${pageContext.request.contextPath}/login" style="text-decoration: none;color: deepskyblue">点击登录</a><br/><br/>
    <form action="${pageContext.request.contextPath}/signuser" method="post">
        <input type="text" placeholder="账号" autocomplete="off" id="user" class="input_1" name="userName"/>
        <span id="userInfo"> &nbsp;</span>
        <input type="password" placeholder="密码" id="pwd" class="input_1" name="password"/>
        <span id="pwdInfo"> &nbsp;</span>
        <input type="password" placeholder="确认密码" id="pwd2" class="input_1"/>
        <span id="pwd2Info"> &nbsp;</span>
        <input type="submit" value="提交" class="input_2" id="but"/>
    </form>
</div>


</body>
</html>
